<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>菜单配置</title>
        <link rel="stylesheet" type="text/css" href="/Plug-in/ext/resources/css/xtheme-slate.css" />
        <style>
            <{section name=li loop=$menucls}>
            .i_<{$menucls[li]|substr:'0':'-4'}>{background-image:url(../img/tree/<{$menucls[li]}>)!important;}
            <{/section}>

            .i_cdpx{background-image:url(../img/sucaiwcom8170000bzc.gif)!important;}
            .ux-icon-combo-icon {
                background-repeat: no-repeat;
                background-position: 0 50%;
                width: 18px;
                height: 14px;
            } 
            /* X-BROWSER-WARNING: this is not being honored by Safari */
            .ux-icon-combo-input {
                padding-left: 25px ! important;

            }

            .x-form-field-wrap .ux-icon-combo-icon {
                top: 3px;
                left: 5px;
                padding-left: 25px;
            }
            .ux-icon-combo-item {
                background-repeat: no-repeat ! important;
                background-position: 3px 50% ! important;
                padding-left: 25px ! important;
            }
            .x-check-group  {
                background:#E7E7E7;
                border-top:1px dotted #B5B8C8;
                border-bottom:1px dotted #B5B8C8;
            }
            .x-radio-group  {
                background:#EEEEEE;
                border-top:1px dotted #B5B8C8;
                border-bottom:1px dotted #B5B8C8;
            }
        </style>
        <{$showjs}>
        <link rel="stylesheet" type="text/css" href="/Plug-in/ext/resources/css/xtheme-slate.css" />
        <link rel="stylesheet" type="text/css" href="../css/main1.css" />
        <link rel="stylesheet" type="text/css" href="../css/multiselect.css" />
        <script type="text/javascript" src="/Plug-in/ext/DDView.js"></script>
        <script type="text/javascript" src="/Plug-in/ext/MultiSelect.js"></script>

        <script language="javascript">
            Ext.namespace('Ext.ux.plugins');

            Ext.ux.plugins.IconCombo = function(config) {
                Ext.apply(this, config);
            };
            // plugin code
            Ext.extend(Ext.ux.plugins.IconCombo, Ext.util.Observable, {
                init:function(combo) {
                    Ext.apply(combo, {
                        tpl:  '<tpl for=".">'
                            + '<div class="x-combo-list-item ux-icon-combo-item '
                            + '{' + combo.iconClsField + '}">'
                            + '{' + combo.displayField + '}'
                            + '</div></tpl>',
 
                        onRender:combo.onRender.createSequence(function(ct, position) {
                            // adjust styles
                            this.wrap.applyStyles({position:'relative'});
                            this.el.addClass('ux-icon-combo-input');
 
                            // add div for icon
                            this.icon = Ext.DomHelper.append(this.el.up('div.x-form-field-wrap'), {
                                tag: 'div', style:'position:absolute'
                            });
                        }), // end of function onRender
 
                        setIconCls:function() {
                            var rec = this.store.query(this.valueField, this.getValue()).itemAt(0);
                            if(rec) {
                                this.icon.className = 'ux-icon-combo-icon ' + rec.get(this.iconClsField);
                            }
                        }, // end of function setIconCls
 
                        setValue:combo.setValue.createSequence(function(value) {
                            this.setIconCls();
                        })
                    });
                } // end of function init
            });
	
            Ext.onReady(function(){
                Ext.QuickTips.init();
                Ext.form.Field.prototype.msgTarget = 'side';



                var parentStore = new Ext.data.Store({   
                    proxy: new Ext.data.HttpProxy({   
                        url: '../table/table.php?op=showalltable'
                    }),   
                    reader: new Ext.data.ArrayReader({   
                        root: 'title',   
                        id: 'table'  
                    }, [   
                        {name: 'table', mapping: 'table'},   
                        {name: 'title', mapping: 'title'}   
                    ])   
                });    
                var combo_use_table = new Ext.form.ComboBox({
                    id : 'parent',
                    name : 'parent',
                    emptyText  :'<{$clg.select}> <{$clg.menupr}>',
                    fieldLabel : '<{$clg.menupr}>',
                    allowBlank :true,
                    width:260,
                    store:new Ext.data.SimpleStore({fields:[],data:[[]]}),
                    mode:'local',
                    value:'<{$tpinfo.title}>',
                    tpl: '<div id="tree2" style="overflow:auto;"></div>',
                    triggerAction:"all"
                });
                var opRoot = new Ext.tree.AsyncTreeNode({
                    id:'0',
                    text:'根'
                });
                var loader = new Ext.tree.TreeLoader({
                    dataUrl:'tree.php',
                    requestMethod:'POST',
                    baseParams:{op:'showparent'}    });

                var opTree = new Ext.tree.TreePanel({
                    anchor : '95%',
                    frame :true,
                    enableDD:false,
                    animate : false,
                    rootVisible :false,
                    useArrows:true,
                    border:false,
                    height:200,
                    containerScroll: true,
                    autoScroll:true,
                    loader:loader,
                    root:new Ext.tree.AsyncTreeNode({
                        id:'0',
                        text:'根'
                    })  //之前定义的根节点
                });
                opTree.on('click',function(node) {
                    //alert(node);
                    combo_use_table.setValue(node.attributes.text);
                    Ext.getCmp('parentid').setValue(node.attributes.id);
                    combo_use_table.collapse();
                    //alert(combo_Hidden.getValue());
                });
                combo_use_table.on('expand',function(){
                    opTree.render('tree2');
                    opTree.root.reload();
                    opTree.root.expand(true,true);
                });
                var expandStore = new Ext.data.JsonStore({
                    id:'comboStore',
                    url: 'tree.php',
                    fields: ['name','value']
                });
                expandStore.load({params:{op: 'show_expand'}});
      

                var addform = new Ext.form.FormPanel({
                    bodyStyle:'padding:5px; background-color: #A2B3CC',
                    autoWidth:true,
                    labelWidth:150,
                    border:false,
                    autoScroll:true,
                    labelAlign:'right',
                    buttunAlign:'left',
                    layout:'form',
                    autoShow:true,
                    plain:true,
                    frame:true,
                    renderTo     : Ext.getBody(),         

                    monitorValid:true,
                    items      : [
                        {
                            id:'id',
                            xtype	   : 'hidden',
                            allowBlank : true,
                            name       : 'id',
                            value		:'<{$tinfo.id}>'},
                        {
                            id:'parentid',
                            xtype	   : 'hidden',
                            allowBlank : true,
                            name       : 'parentid',
                            value		:'<{$tinfo.parentid}>'},	
                        {
                            id:'title',
                            xtype	   : 'textfield',
                            fieldLabel : '<{$clg.menutitle}>',
                            name       : 'title',
                            ctCls:"x-radio-group",
                            allowBlank : false,
                            blankText  :'<{$clg.menutitle}> <{$clg.bnwk}>',
                            width      : 165,
                            value:'<{$tinfo.title}>'},
                        {
                            id:'url',
                            xtype	   : 'textfield',
                            fieldLabel : '<{$clg.menuurl}>',
                            name       : 'url',
                            width      : 300,
                            value:'<{$tinfo.url}>'},
                        {
                            // Use the default, automatic layout to distribute the controls evenly
                            // across a single row
                            xtype: 'radiogroup',
                            fieldLabel: '<{$clg.menuleaf}>',
                            ctCls:"x-radio-group",
                            itemCls:"x-radio-group",
                            height:20,
                            items: [
                                {boxLabel: '<{$clg.no}>',itemCls:"x-radio-group", name: 'leaf',inputValue: 0<{if $tinfo.leaf=='0'}>, checked: true<{/if}>},
                                {boxLabel: '<{$clg.yes}>',itemCls:"x-radio-group", name: 'leaf',inputValue: 1<{if $tinfo.leaf=='1' || $tinfo.leaf==''}>, checked: true<{/if}>}
                            ]
                        },{
                            id:'lg',
                            xtype	   : 'textfield',
                            fieldLabel : '<{$clg.lg}>',
                            name       : 'config[lg]',
                            width      : 300,
                            value:'<{$config.lg}>'},
                        {
                            xtype:'combo',
                            name:'cls',
                            fieldLabel:'<{$clg.menucls}>',
                            store: new Ext.data.SimpleStore({
                                fields: ['iconname', 'iconFlag'],
                                data: [
                                        <{section name=li loop=$menucls}>
                                        ['<{$menucls[li]}>', 'i_<{$menucls[li]|substr:'0':'-4'}>'],
                                        <{/section}>
                                        ['default', '']
                                ]
                            }),
                            plugins:new Ext.ux.plugins.IconCombo(),
                            valueField: 'iconname',
                            displayField: 'iconname',
                            iconClsField: 'iconFlag',
                            triggerAction: 'all',
                            //					readOnly:true,
                            value:"<{if $tinfo.cls==''}>default<{else}><{$tinfo.cls}><{/if}>",
                            mode: 'local'/*,
                            listeners:{
                                        select:function(_combo,_record,_index){
                                            alert(_record.get('iconFlag'));
                                            if(_index==0){alert(_combo.getValue());}

                                            }
                                    }
         */				},{
                            // Use the default, automatic layout to distribute the controls evenly
                            // across a single row
                            xtype: 'checkboxgroup',
                            fieldLabel: '<{$clg.menuright}>',
                            ctCls:"x-radio-group",
						
                            height:20,
                            items: [
                                {boxLabel: '<{$clg.new}>', itemCls:"x-radio-group",name: 'shield_add',inputValue:1<{if $tinfo.shield_add=='1'}>, checked: true<{/if}>},
                                {boxLabel: '<{$clg.edit}>',itemCls:"x-radio-group", name: 'shield_edit',inputValue:1<{if $tinfo.shield_edit=='1'}>, checked: true<{/if}>},
                                {boxLabel: '<{$clg.del}>', itemCls:"x-radio-group",name: 'shield_del',inputValue:1<{if $tinfo.shield_del=='1'}>, checked: true<{/if}>},
                                {boxLabel: '<{$clg.menushow}>',itemCls:"x-radio-group", name: 'is_show',inputValue:1<{if $tinfo.is_show=='1' || $tinfo.is_show==''}>, checked: true<{/if}>},
                                {boxLabel: '<{$clg.menudel}>', itemCls:"x-radio-group",name: 'del',inputValue:1<{if $tinfo.del=='1'}>, checked: true<{/if}>}
                            ]
                        },combo_use_table,	
                        {   
                            fieldLabel: '<{$clg.sjmx}>',   
                            xtype:'combo',
                            style:'text-align:left',
                            store: parentStore,   
                            valueField :"table",   
                            displayField: "title",   
                            mode: 'local',
                            readOnly:true,
                            forceSelection: true,//必须选择一项   
                            emptyText:'<{$clg.qing}><{$clg.select}>...',//默认值   
                            hiddenName:'table',//hiddenName才是提交到后台的input的name   
                            editable: false,//不允许输入   
                            triggerAction: 'all',//因为这个下拉是只能选择的，所以一定要设置属性triggerAction为all，不然当你选择了某个选项后，你的下拉将只会出现匹配选项值文本的选择项，其它选择项是不会再显示了，这样你就不能更改其它选项了。   
                            //allowBlank:false,//该选项值不能为空   
                            id : 'table_id',   
                            name: 'usrtable',   
                            width: 120,   
                            listeners:{     
                                render:function(combo){
                                    parentStore.on('load', function() {   
                                        combo.setValue(<{if $tinfo.table!='0'}><{$tinfo.table}><{/if}>);   
                                    }); 
                                    parentStore.load();									
                                }
                            }   
                        },{
                            // Use the default, automatic layout to distribute the controls evenly
                            // across a single row
                            xtype: 'checkboxgroup',
                            fieldLabel: '实时房价/房态',
                            ctCls:"x-radio-group",
                            height:20,
                            items: [
                                {boxLabel: '房价', itemCls:"x-radio-group",name: 'config[realtime_price]',inputValue:1<{if $config.realtime_price=='1'}>, checked: true<{/if}>},
                                {boxLabel: '房态', itemCls:"x-radio-group",name: 'config[realtime_room]',inputValue:1<{if $config.realtime_room=='1'}>, checked: true<{/if}>},
                            ]
                        },{
                            // Use the default, automatic layout to distribute the controls evenly
                            // across a single row
                            xtype: 'checkboxgroup',
                            fieldLabel: 'Excel导出',
                            ctCls:"x-radio-group",
                            height:20,
                            items: [
                                {boxLabel: '允许', itemCls:"x-radio-group",name: 'config[excelExport]',inputValue:1<{if $config.excelExport=='1'}>, checked: true<{/if}>},
                            ]
                        },
                        {
                            xtype:'fieldset',
                            title: '<{$clg.menukz}>',
                            id:'expand_set',
                            checkboxToggle:true,
                            autoHeight:true,
                            collapsed: true,
                            defaults: {width:300},
                            defaultType: 'textfield',
                            items :[{
                                    xtype: 'checkboxgroup',
                                    fieldLabel: '<{$clg.menuisex}>',
                                    height:20,
                                    ctCls:"x-radio-group",
		
                                    items: [
                                        {boxLabel: '<{$clg.yes}>', id:'is_expand',itemCls:"x-radio-group",name: 'is_expand',inputValue:1<{if $tinfo.is_expand=='1'}>, checked: true<{/if}>}
                                    ]
                                },{
                                    xtype:'multiselect',
                                    id : 'expand',
                                    name : 'expand',
                                    fieldLabel : '<{$clg.menuex}>',
                                    allowBlank : true,
                                    height:110,
                                    dataFields: ['name','value'],
                                    store:expandStore,
                                    data:expandStore.data,
                                    displayField: "value",
                                    valueField:"name",
                                    mode:'local',
                                    triggerAction:"all",
                                    listeners:{     
                                        render:function(){  
                                            //alert(Ext.getCmp('expand_id').setValue("<{$tinfo.expand}>"));
                                            //alert(Ext.getCmp('expand_id').setValue("<{$tinfo.expand}>"));
                                            /*alert('undefined'==Ext.getCmp('expand_id').setValue("<{$tinfo.expand}>"));
                                             */	
                                            function setex(){
                                                Ext.getCmp('expand').setValue("<{$tinfo.expand}>");
                                                if(Ext.getCmp('expand').getValue()=="<{$tinfo.expand}>"){
                                                    return true;
                                                }
                                                else{
                                                    return setTimeout(setex,10);
                                                }
                                            }
                                            if(''=='<{$tinfo.expand}>'){
                                                return true;
                                            }else{
                                                setex();
                                            }
															
                                        }
														
                                    }   
                                }]
                        }		],
                    buttons: [{
                            text: '<{$clg.save}>',
                            handler: function(){
                                if(addform.form.isValid()){
                                    addform.form.doAction('submit',{
                                        url:'tree.php',
                                        method:'POST',
                                        params:{op:'save_baseinfo'},
                                        waitMsg:'正在提交....',
                                        success:function(form,action){
                                            if (action.result.msg=='ok') {
                                                var E=Ext.Msg.alert('提示[notice]','数据更新成功！<BR>Data updated Success!',function(){
                                                    //parent.Ext.getCmp('tree').root.reload();
                                                    //parent.Ext.getCmp('tree').expandAll();
                                                });
                                            } else {
                                                Ext.Msg.alert('失败',action.result.msg);
                                            }
                                        },
                                        //提交失败的回调函数
                                        failure:function(){
                                            Ext.Msg.alert('错误','数据提交错误！');
                                        }
                                    });
                                }
                            },
                            formBind:true
                        },{
                            text: '<{$clg.reset}>',
                            handler: function(){
                                addform.getForm().reset();
		
                            }
                        }]
                });
	
                /*	
        SetInterval(function(){
                             //Ext.getCmp('expand_id').setValue("<{$tinfo.expand}>");
                             alert('w');
                             },2000);*/

            });
	
        </script>
    </head>
    <body >
        <div id="tree-config"></div>
    </body>
</html>